import audioManager from '../../general/audioManager'
import GamePanel from '../../hall/gamePanel';

const { ccclass, property } = cc._decorator;

@ccclass
export default class game100player extends cc.Component {
    @property(cc.Node)
    comNode: cc.Node = null;
    @property(cc.AudioClip)
    mp3: cc.AudioClip[] = []

    gamecom: any;
    protected onLoad(): void {
        this.gamecom = this.comNode.getComponent('game100')
    }

    onCollisionEnter(A, B) {
        // console.log(A.node.name)
        this.gamecom.player.stopAllActions();
        if (A.node.name == 'wall') {
            this.gamecom.jump();
            this.gamecom.usecount++;
        } else if (A.node.name == 'fish') {
            this.node.group = 'default'
            audioManager.playEffect(this.mp3[0])
            console.log('播放')
            let fish: cc.Node = A.node
            let fishcom = fish.getComponent('game100fish')
            fishcom.movestate = false;
            fish.parent = this.node;
            fish.setPosition(0, 0)
            fish.setScale(0.5, 0.5)
            fish.angle = -90
            this.gamecom.jump(() => {
                let score = Number(this.gamecom.score_label.string) + fishcom.value * this.node.childrenCount
                GamePanel.instance.updateScore(score)
                this.node.removeAllChildren();
            });
        }
    }
}
